#include "StdAfx.h"
#include "ResourceDocument.h"

#include "Parser.h"


static const CHAR g_szDefaultScript[] =
	"#include <winres.h>\r\n"
	"#include \"Resource.h\"\r\n";

static const CHAR g_szDefaultHeader[] =
	"#pragma once\r\n";


VOID CResourceDocument::ReadText(CFile &rFile, CStringA &rString)
{
	UINT uLength = (UINT)rFile.GetLength();
	CStrBufA pBuffer(rString, uLength, CStrBufA::SET_LENGTH);
	rFile.Read(pBuffer, uLength);
}


CResourceDocument::CResourceDocument()
{
	Clear();
}


VOID CResourceDocument::Clear()
{
	m_strScript = g_szDefaultScript;
	m_strHeader = g_szDefaultHeader;
}

VOID CResourceDocument::Load(CFile &rScriptFile, CFile &rHeaderFile)
{
	ReadText(rScriptFile, m_strScript);
	ReadText(rHeaderFile, m_strHeader);
}

VOID CResourceDocument::Save(CFile &rScriptFile, CFile &rHeaderFile)
{
	rScriptFile.Write(m_strScript, m_strScript.GetLength() * sizeof(CHAR));
	rHeaderFile.Write(m_strHeader, m_strHeader.GetLength() * sizeof(CHAR));
}
